﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace VoltGameEditor
{
    public partial class contole : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public contole()
        {
            InitializeComponent();
        }

        public void commands(string command)
        {
            if (command.Contains("/") == false)
            {
                this.rtb_output.Text += "\nCommands must have a '/' before it.";
                return;
            }
            else
            {
                string[] cmd = command.Split(new char[]{' '});
                cmd[0] = cmd[0].Remove(0, 1);
                switch (cmd[0])
                {
                    case "help":
                        {
                            if (System.IO.File.Exists("VoltGE.chm"))
							{
								rtb_output.Text += "\n Launching VoltGE.chm...";
								Process proc = new Process();
								proc.StartInfo.FileName = "VoltGE.chm";
								proc.Start();
							}
							else
								rtb_output.Text += "\n VoltGE.chm is missing! Did you delete it?";
                            break;
                        }
                    case "close":
                        {
                            this.Hide();
                            break;
                        }
					case "quit":
						Program.mainWin.Close();
						break;
                    case "grid":
                        {
                            if (cmd.Length == 1)
                            {
                                //rtb_output.Text += "\n - Grid Size = " + map_editor.grid_size.Text;
                            }
                            else
                            {
                                //map_editor.ChangeGrid(float.Parse(cmd[1]));
                            }
                            
                            break;
                        }
                    case "":
                        {
                            break;
                        }
                    default:
                        {
                            this.rtb_output.Text+="\n++Unknown Command '"+command+"'";
                            break;
                        }
                }
                this.textBox1.Text = "/";
                this.textBox1.Select(1, 0);
            }
        }

		public void ShowConsole(int TabIndex)
		{
			Program.Console.Show(Program.mainWin.dp_docs);
			if (TabIndex == 0)
				Program.Console.Tabs.SelectedIndex = 0;
			else if (TabIndex == 1)
				Program.Console.Tabs.SelectedIndex = 1;
		}

        private void contole_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Oemtilde)
            {
                e.SuppressKeyPress = true;
                this.Hide();
            }
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.commands(textBox1.Text);
            }
        }

        private void contole_Activated(object sender, EventArgs e)
        {
            textBox1.Focus();
        }

		private void contole_Load(object sender, EventArgs e)
		{

		}

    }
}
